#!/bin/awk

$0 ~ syscall {
	src = $0
	while (match(src, "{") == 0) {
		getline  tmp
		src = src tmp
	}

	n = gensub(/^[[:blank:]]*SYSCALL_DEFINE(.).*$/, "\\1", 1, src)
	name = gensub(/^[[:blank:]]*SYSCALL_DEFINE.\(([_[:alnum:]]+).*$/, "\\1", 1, src)
	src = substr(src, index(src, name) + length(name))
	tail = gensub(/^.*({)(.*)$/, "\\2", 1, src)
	sub(/)[[:blank:]]*{.*/, "", src)

	print "long " prefix name "(const struct pt_regs *regs)\n{\n"
	if (n > 0) {
		arg[1] = arg1
		arg[2] = arg2
		arg[3] = arg3
		arg[4] = arg4
		arg[5] = arg5
		arg[6] = arg6
		split(src, tv, ",")
		for (i = 1; i <= n; i++)
			print tv[i*2], tv[i*2+1], "= __SC_CAST(" tv[i*2] ", regs->" arg[i] ");\n"
	}
	print tail "\n"
}
$0 !~ syscall { print }
